// packageA/pages/orgIntroduce/orgIntroduce.js
const app = getApp();
var WxParse = require('../../../wxParse/wxParse.js');
import util from '../../../utils/util.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabActive:0,
    orgid:'',
    list:[],
    member:[],
    detail:{},
    showBox:false,
    member1:[],
  },
  showbtn(){
    this.toggle('showBox', true)
  },
  typeClose(){
    this.toggle('showBox', false)
  },
  tabBtn(e){
    var type = e.currentTarget.dataset.type
    if (type != this.data.tabActive){
      this.toggle('tabActive',type)
    }
  },
  toggle(type, val) {
    this.setData({
      [type]: val
    });
  },
  getcommerceIntroduce(){
    var that = this
    app.req({
      url: "orgmini/business/commerceIntroduce",
      data: {
        orgId: that.data.orgid
      },
      success: function (res) {
        if (200 == res.code) {
          that.toggle("detail", res.data);
          that.toggle("member", res.data.member);
          that.toggle("member1", res.data.member);
          if (that.data.detail.intro){
            var rich = that.data.detail.intro
            WxParse.wxParse('rich', 'html', rich, that, 5);
          }
          if (that.data.detail.rule){
            var rule = that.data.detail.rule
            WxParse.wxParse('rule', 'html', rule, that, 5);
          }
          if (that.data.detail.org){
            var org = that.data.detail.org
            WxParse.wxParse('org', 'html', org, that, 5);
          }
          for (var i of that.data.member){
            var reg = new RegExp("<[^>]+>", "g");
            i.a = i.achievement.replace(reg, '');
          }
          that.toggle("member", that.data.member);
          console.log('会员', that.data.member, that.data.detail)
        }
      }
    });
  },
  getactivities(){
    var that = this
    app.req({
      url: "orgmini/businessGov/activities",
      data: {
        entityId: that.data.orgid,
        type:2100,
        pageNumber: that.data.pageNumber,
        pageSize:10,
      },
      success: function (res) {
        if (200 == res.code) {
          var list = res.data
        for (var item of list) {
          var d = new Date(item.startTime)
          item.year = d.getFullYear()
          item.month = d.getMonth() + 1
          item.date = d.getDate();
        }
          if(that.data.pageNumber==1){
            that.toggle('list', list)
          }else{
            that.toggle('list', that.data.list.concat(list))
          }
         console.log('商会荣誉',list)
        }
      }
    });
  },
  tohonor(e){
    wx.navigateTo({
      url: '/packageA/pages/orgHonor/orgHonor?id='+e.currentTarget.dataset.id,
    })
  },
  toMember(e){
    var index = e.currentTarget.dataset.index
    wx.setStorageSync('member', this.data.member1[index]);
    wx.navigateTo({
      url: '/packageA/pages/orgMember/orgMember'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.toggle('orgid', options.id)
    this.getcommerceIntroduce()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.toggle('pageNumber', 1) 
    this.getactivities()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    if(that.data.tabActive==4){
      that.toggle('pageNumber', that.data.pageNumber + 1) 
      that.getactivities()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})